//
//  TitleButton.swift
//  WeiBo(Swift)
//
//  Created by 周成龙 on 16/9/23.
//  Copyright © 2016年 ZCL. All rights reserved.
//

import UIKit

class TitleButton: UIButton {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupBtn()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupBtn()
    }
    
    private func setupBtn() {
        setTitleColor(UIColor.gray, for: UIControlState.normal)
        setImage(UIImage(named: "navigationbar_arrow_down"), for: UIControlState.normal)
        setImage(UIImage(named: "navigationbar_arrow_up"), for: UIControlState.selected)
        sizeToFit()
    }
    
    override func setTitle(_ title: String?, for state: UIControlState) {
        super.setTitle((title ?? "") + "  ", for: state)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        // 图片 + 文字 => 文字 + 图片
        self.titleLabel?.frame.origin.x = 0
        self.imageView?.frame.origin.x = (self.titleLabel?.frame.width)!
    }
}
